#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

typedef int ElementType;
typedef struct LIST List;
struct LIST{
	ElementType Elm;
	List *Next;
	List *Tail;
};

List *ListInit(void);
void Add(List*,ElementType);
void ReverseList(List*);
void PrtList(List*);


List *ListInit(void){
	List *l=malloc(sizeof(List));
	l->Next=NULL;
	l->Tail=l;
	return l;
}
void Add(List *l,ElementType x){
	List *new=malloc(sizeof(List));
	new->Elm=x;
	new->Next=NULL;
	l->Tail->Next=new;
	l->Tail=new;
	return;
}
void ReverseList(List *l){
	List *current,*pre,*tmp;
	pre=NULL,current=l->Next;
	if( l->Next )
		l->Tail=l->Next;
	while( current ){
		tmp=current->Next;
		current->Next=pre;
		pre=current;
		current=tmp;
	}
	l->Next=pre;
	return;
}
void PrtList(List *l){
	printf("\nTail is %d\n",l->Tail->Elm);
	while( l->Next ){
		printf("%3d-->",l->Next->Elm);
		l=l->Next;
	}
	printf("NULL");
	return;
}


int main(void){
	List *l=ListInit();
	int i=10;
	while( i-- ){
		Add(l,i);
	}
	PrtList(l);
	printf("\nAfter Reverse\n");
	ReverseList(l);
	PrtList(l);
	return 0;
}
